<?php

namespace app\common\model\game;

use app\common\enum\YesNoEnum;
use app\common\model\BaseModel;
use think\facade\Cache;
use think\model\concern\SoftDelete;

/**
 * 管理模型
 * Class Banner
 * @package app\common\model\game;
 */
class Banner extends BaseModel
{
    use SoftDelete;

    protected $deleteTime = 'delete_time';


    /**
     * @notes 设置图片域名
     * @param $value
     * @param $data
     * @return array|string|string[]|null
     * @author 段誉
     * @date 2022/9/28 10:17
     */
    public function getContentAttr($value, $data)
    {
        return get_file_domain($value);
    }


    /**
     * @notes 清除图片域名
     * @param $value
     * @param $data
     * @return array|string|string[]
     * @author 段誉
     * @date 2022/9/28 10:17
     */
    public function setContentAttr($value, $data)
    {
        return clear_file_domain($value);
    }

    /**
     * @notes 是否显示描述
     * @param $value
     * @param $data
     * @return string
     * @date 2024/7/17 19:18
     */
    public function getShowDescAttr($value, $data)
    {
        return $data['is_show'] ? '显示' : '不显示';
    }


    /**
     * @notes 获取详情
     * @param $id
     * @return array
     * @date 2024/7/15 0:39
     */
    public static function getSoftwareDetailArr(int $id)
    {
        $info = Banner::where(['id' => $id, 'is_show' => YesNoEnum::YES])
            ->field('id, title, image, out_url, resource_id, sort, is_show, create_time, update_time')
            ->findOrEmpty();

        if ($info->isEmpty()) {
            return [];
        }

        return $info->toArray();
    }


    /**
     * 根据appid获取轮播图
     * @param $appid
     * @param $update
     * @return array|mixed
     */
    public static function getLists()
    {

        $lists = Banner::where(['is_show' => YesNoEnum::YES])
            ->field('title, image, out_url, resource_id, sort, is_show')
            ->order(['sort' => 'desc', 'id' => 'desc'])
            ->select()
            ->toArray();

        return $lists;
    }

}